package com.systemic.controller;

import com.systemic.core.ResponseResult;
import com.systemic.pojo.MindfulnessLog;
import com.systemic.pojo.MindfulnessMedia;
import com.systemic.service.MindfulnessLogService;
import com.systemic.vo.PageVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: MindfulnessLogController
 * @Description:
 * @Author:
 * @CreateTime: 2024-01-31 18:54
 * @Version:
 **/
@RestController
@RequestMapping("/mindfulnessLog")
public class MindfulnessLogController {

    @Resource
    private MindfulnessLogService service;

    /**
     * 新增
     * @param mindfulnessLog
     * @return
     */
    @PostMapping("/add")
    public ResponseResult<String> add(@RequestBody MindfulnessLog mindfulnessLog){
        int row = service.add(mindfulnessLog);
        return row!=0 ? ResponseResult.success("新增成功") : ResponseResult.failed("新增失败");
    }


    /**
     * 批量删除
     * @param ids
     * @return
     */
    @GetMapping("/deleteList/{ids}")
    public ResponseResult<String> deleteList(@PathVariable("ids") Integer[] ids){
        int row = service.deleteList(ids);
        return row!=0 ? ResponseResult.success("删除成功") : ResponseResult.failed("删除失败");
    }

    /**
     * 修改
     * @param mindfulnessLog
     * @return
     */
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody MindfulnessLog mindfulnessLog){
        int row = service.update(mindfulnessLog);
        return row!=0 ? ResponseResult.success("修改成功") : ResponseResult.failed("修改失败");
    }

    /**
     * 分页查询（根据用户id）
     * @param pageVo
     * @return
     */
    @PostMapping("/selectByAuthor")
    public ResponseResult<List<MindfulnessLog>> selectByAuthor(@RequestBody PageVo pageVo){
        List<MindfulnessLog> res = service.selectByAuthor(pageVo);
        return !res.isEmpty() ? ResponseResult.success(res) : ResponseResult.failed();
    }

}
